package cn.stylefeng.guns.modular.make.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.make.entity.MakeRailwayPlatform;
import cn.stylefeng.guns.modular.make.mapper.MakeRailwayPlatformMapper;
import cn.stylefeng.guns.modular.make.model.params.MakeRailwayPlatformParam;
import cn.stylefeng.guns.modular.make.model.result.MakeRailwayPlatformResult;
import  cn.stylefeng.guns.modular.make.service.MakeRailwayPlatformService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 月台管理 服务实现类
 */
@Service
public class MakeRailwayPlatformServiceImpl extends ServiceImpl<MakeRailwayPlatformMapper, MakeRailwayPlatform> implements MakeRailwayPlatformService {

    @Override
    public void add(MakeRailwayPlatformParam param){
        MakeRailwayPlatform entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(MakeRailwayPlatformParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(MakeRailwayPlatformParam param){
        MakeRailwayPlatform oldEntity = getOldEntity(param);
        MakeRailwayPlatform newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public MakeRailwayPlatformResult findBySpec(MakeRailwayPlatformParam param,Long operateId){
        return this.baseMapper.findBySpec(param,operateId);
    }

    @Override
    public List<MakeRailwayPlatformResult> findListBySpec(MakeRailwayPlatformParam param,Long operateId){
        return this.baseMapper.findListBySpec(param,operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(MakeRailwayPlatformParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(MakeRailwayPlatformParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private MakeRailwayPlatform getOldEntity(MakeRailwayPlatformParam param) {
        return this.getById(getKey(param));
    }

    private MakeRailwayPlatform getEntity(MakeRailwayPlatformParam param) {
        MakeRailwayPlatform entity = new MakeRailwayPlatform();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
